<?php

class DefaultController {

	protected $load;

	public function __construct() {}

	public function index() {}

	public function view( $name, $core = null )
	{
		try
		{
			if ( $core )
			{
				if ( @!include_once( CORE_VIEW_PATH . $name . '.php' ) )
					throw new Exception();
			}
			else
			{
				if ( @!include_once( VIEW_PATH . $name . '.php' ) )
					throw new Exception();
			}
		}
		catch ( Exception $e )
		{
			if ( @!include_once( VIEW_PATH . '404view.php' ) )
					include_once( CORE_VIEW_PATH . '404view.php' );
			exit;
		}
	}

	public function controller( $name, $action = null, $core = null )
	{
		try
		{
			if ( $core )
			{
				if ( @!include_once( CORE_CONTROLLER_PATH . $name . '.php' ) )
					throw new Exception();
			}
			else
			{
				if ( @!include_once( CONTROLLER_PATH . $name . '.php' ) )
					throw new Exception();
			}
		}
		catch ( Exception $e )
		{
			if ( @!include_once( VIEW_PATH . '404controller.php' ) )
					include_once( CORE_VIEW_PATH . '404controller.php' );
			exit;
		}
	}

	public function model( $name, $core = null )
	{
		try
		{
			if ( $core )
			{
				if ( @!include_once( CORE_MODEL_PATH . $name . '.php' ) )
					throw new Exception();
			}
			else
			{
				if ( @!include_once( MODEL_PATH . $name . '.php' ) )
					throw new Exception();
			}
		}
		catch ( Exception $e )
		{
			if ( @!include_once( VIEW_PATH . '404model.php' ) )
					include_once( CORE_VIEW_PATH . '404model.php' );
			exit;
		}
	}

	public function getChildrenLoadInstance()
	{
		if ( $this->load )
			return;
		$this->load = new DefaultController();
	}

}

?>